﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="change_passwordform.aspx.cs"
    Inherits="form_usermanagement_change_passwordform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Change Password Form</title>
    <link href="<%= ResolveClientUrl("css/validationEngine.jquery.css") %>" rel="stylesheet"
        type="text/css" />
    <script src="<%= ResolveClientUrl("script/helper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveClientUrl("script/jquery.validationEngine.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveClientUrl("script/autoNumeric-1.7.5.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveClientUrl("script/languages/jquery.validationEngine-en.js") %>"
        type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {

            // binds form submission and fields to the validation engine
            jQuery("#form1").validationEngine();

            //            jQuery("#form1").submit();
            if ($("#form1").validationEngine('validate')) { }
            else jQuery("#form1").submit();

        });

        $("#save").click(function () {

            if ($("#form1").validationEngine('validate')) {

                var password = $('#<%= txtNewPassword.ClientID %>').val();
                var verifypassword = $('#<%= txtVerifyPassword.ClientID %>').val();
                var userId = '<%= base.UserID  %>';
                if (verifypassword == password) {

                    $.ajax({
                        type: 'POST',
                        url: 'ajaxhandler/usermanagement/sys_t_user.ashx?method=getsamepassword&id=' + userId+'&password='+password,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (data) {

                            if (data.samepassword == "true") {
                                alert("Password baru tidak boleh sama dengan password lama..!!");

                                $('#<%= txtNewPassword.ClientID %>').val('');
                                $('#<%= txtVerifyPassword.ClientID %>').val('');
                                $('#<%= txtNewPassword.ClientID %>').focus();
                            }
                            else {

                                var handlerUrl = '<%= ResolveClientUrl("ajaxhandler/usermanagement/sys_t_user.ashx") %>';

                                var userId = '<%= base.UserID %>';
                                var password = $('#<%= txtNewPassword.ClientID %>').val();

                                var param = '&userid=' + userId + '&password=' + password;

                                CallAjax(handlerUrl, "?method=changepassword" + param);

                                parent.$('#dialog').dialog("close");


                            }
                            
                        },
                        error: function () {
                            alert('Error!');
                        }
                    });



                }
                else {

                    alert("New Password dan Verify Password harus sama ..!!");
                   $('#<%= txtNewPassword.ClientID %>').val('');
                   $('#<%= txtVerifyPassword.ClientID %>').val('');
                   $('#<%= txtNewPassword.ClientID %>').focus(); 

                }
            }


            return false;
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="0" cellpadding="1" cellspacing="1">
            <tr>
                <td>
                    User Name
                </td>
                <td style="padding-left: 20px">
                    :
                </td>
                <td style="padding-left: 20px">
                    <asp:TextBox ID="txtUserName" runat="server" Enabled="false" Width="200px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    New Password
                </td>
                <td style="padding-left: 20px">
                    :
                </td>
                <td style="padding-left: 20px">
                    <asp:TextBox ID="txtNewPassword" CssClass="validate[required]" runat="server" TextMode="Password" MaxLength="50"
                        Width="200px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Verify Password
                </td>
                <td style="padding-left: 20px">
                    :
                </td>
                <td style="padding-left: 20px">
                    <asp:TextBox ID="txtVerifyPassword" CssClass="validate[required]" runat="server" TextMode="Password" MaxLength="50"
                        Width="200px"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
    <br />
    <br />
    <div>
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td align="right">
                    <a href="#" id="save" class="dialog_link ui-state-default ui-corner-all"><span class="ui-icon ui-icon-disk">
                    </span>Save</a>
                </td>
            </tr>
        </table>
        <asp:HiddenField ID="hfUserID" runat="server" />
    </div>
    </form>
</body>
</html>
